#!/bin/bash

#控制台

#获取进程号
#pid=`ps -aux|grep app.py| grep -v grep | awk '{print $2}'`
pid=`ps aux | grep gunicorn | grep -v grep | awk '{print $2}'`
#echo $pid

case $1 in
	"start")
	if [ "${pid}" == "" ]; then
#		sh -c "source .venv/bin/activate &&nohup python3 app.py > /dev/null 2>&1 &"
    sh -c "source .venv/bin/activate && gunicorn -c gunicorn_config.py -D app:app"
		echo "启动中"
		/usr/code/sh/java/func_check_app.sh 8110
		echo "启动成功"
	else
		echo "程序已启动"	
	fi
	;;
	"restart")
	$0 stop;
	$0 start;
	;;
	"stop")
	if [ "${pid}" == "" ]; then	
		echo "程序已停止"
	else
		echo "进程号：${pid}，停止中"
#		kill $pid
    pkill gunicorn
		sleep 1
		echo "进程号：${pid}，停止成功"
	fi
	;;
	*)
	echo "usage:	console command"
	echo "command:	[start|restart|stop]"
	echo "example	./console start"
	;;
esac